<?php

require '../vendor/autoload.php';

use Gnway\Util\Concurrent\Executors;
use Gnway\Util\Concurrent\Process;

$pool = Executors::newPool();
for ($i = 0; $i < 5; $i++) {
  $task = new class extends Process {
    public function run(): void
    {
      while (!$this->interrupted) {
        echo date('H:i:s') . ', pid: ' . getmypid() . PHP_EOL;
        usleep(1000000);
      }
    }
  };
  $pool->submit($task);
}
$pool->start();

sleep(1);

echo '2 seconds after to terminal the process....' . PHP_EOL;

sleep(2);

$pool->shutdown();

echo 'Shutdown success!' . PHP_EOL;

exit(0);